<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%String path = request.getContextPath(); %>

<div class="callout callout-left">
  <span class="callout-title text-muted">密钥分配查看</span><!-- &nbsp;<span class="glyphicon glyphicon-question-sign"></span> -->
  <a class="btn btn-primary"   href="javascript:;" id="export_excel" style="margin-left: 35px;"><span class="glyphicon glyphicon-export">&nbsp;导出excel</span></a>
</div>

<div class="callout callout-white">
<div class="table-responsive center-block" style="max-width: 500px;">
  <table class="table table-bordered" id="t_excel">
    <thead>
      <tr>
        <th>#</th>
      	<th>软件名称</th>
        <th>总密钥数量</th>
        <th>已分配</th>
        <th>已激活</th>
      </tr>
    </thead>
    <tbody id="keys_content">
      
    </tbody>
  </table>
  </div>
</div>

<script>
require.config({
	baseUrl: '<%=path %>/js',
	paths: {
		jquery: 'jquery-1.9.1.min',
		commmon: 'common',
		bootstrapswitch: 'bootstrap-switch.min'
	}
});
require(['jquery', 'common', 'bootstrapswitch'], function($, common) {
//console.log("密钥总量模块载入");

var workspace = function() {
	
	var dataOpt;
	var softwares;
	
	var init = function() {
		dataOpt = common.dataOpt;
		softwares = common.ajaxLoadData(dataOpt.softwareOpt);
		
		_initsoftNameTable();
		common.exportExcel("密钥数量统计");
	}
	
	var _initsoftNameTable = function() {
		var template = "<tr><th>#row#</th><td>#softName#</td><td>#numLicense#</td>" +
		  "<td>#assignedLicense#</td><td>#actAmount#</td></tr>";

		var row = 1;
		var html = "";
		softwares.forEach(function(software) {
			dataOpt.userActiveSoftOpt.data = {
				"softName": software["softName"],
				"status": encodeURI(encodeURI("已激活"))
			}
			var userActSofts = common.ajaxLoadData(dataOpt.userActiveSoftOpt);
			dataOpt.userActiveSoftOpt.data = {}
			
			var actAmount = userActSofts.length;
			var thisT = template;
			thisT = thisT.replace(/#row#/g, row++).replace(/#softName#/g, software["softName"]).replace(/#actAmount#/g, actAmount)
				.replace(/#numLicense#/g, software["numLicense"]).replace(/#assignedLicense#/g, software["assignedLicense"]);
			html += thisT;
		});
		$("#keys_content").html(html);
	}
	
	return {
		init: init
	}
}();
	
$(function() { workspace.init(); });

});

requirejs.onError = function (err) {  
  console.error(err);
  if (err.requireType === 'timeout') {
      console.error('modules: ' + err.requireModules);
  }
  throw err;
}
</script>